import originalOrder from '@/assets/originalOrder.png';
import adjustOrder from '@/assets/adjustOrder.png';
import hedgingOrder from '@/assets/hedgingOrder.png';
import retorOrder from '@/assets/retorOrder.png';
import splitOrder from '@/assets/splitOrder.png';
import newOrder from '@/assets/newOrder.png';
import makeupOrder from '@/assets/makeupOrder.png';
import { clientOption, statusOption } from '@/views/project/model/selectData';
import { getDepartmentAll } from '@/api/config';
import { getAccountBelong, platformList } from '@/api/select';
import { getProjectTypes } from '@/api/project';
import { ACTIVE_ORDERS, SUB_ACTIVE_ORDERS } from '@/utils/const/order';
export default {
  data() {
    return {
      curActiveOrder: ACTIVE_ORDERS.CHANNEL,
      curSubActiveOrder: SUB_ACTIVE_ORDERS.ALL_ORDER,
      deptTreeList: [], // 所属部门
      orderPlatformOption: [], // 下单平台
      projectTypeOption: [], // 项目类型
      accountBelongs: [] // 账号归属
    };
  },
  computed: {
    orderTypeImg() { // 订单类型
      return [{
        type: 0,
        img: originalOrder,
        bg: '#EFF4FF',
        color: '#406EFF'
      }, {
        type: 1,
        img: splitOrder,
        bg: '#E2F8F2',
        color: '#31CC9C'
      }, {
        type: 2,
        img: hedgingOrder,
        bg: '#FFEFF0',
        color: '#FF4E5F'
      }, {
        type: 3,
        img: newOrder,
        bg: '#F9ECFF',
        color: '#9B5BED'
      }, {
        type: 4,
        img: retorOrder,
        bg: '#FFF8EA',
        color: '#FFBC3D'
      }, {
        type: 5,
        img: adjustOrder,
        bg: '#FFF2EB',
        color: '#FD8546'
      }, {
        type: 6,
        img: originalOrder,
        bg: '#FDEFE9',
        color: '#FD8546'
      }, {
        type: 7,
        img: makeupOrder,
        bg: '#FFE6F2',
        color: '#F861AD'
      }];
    },
    reviewState() {
      return [{
        status: 0,
        reviewColor: '#31CC9C'
      }, {
        status: 1,
        reviewColor: '#406EFF'
      }, {
        status: 2,
        reviewColor: '#FD8546'
      }];
    },
    getSelectedNum({ curActiveOrder }) {
      let num = 0;
      switch (curActiveOrder) {
        case ACTIVE_ORDERS.CHANNEL:
          num = this.selectedData.channelTable.length;
          break;
        case ACTIVE_ORDERS.PROJECT_CHANNEL:
          num = this.selectedData.projectChannelTable.length;
          break;
        case ACTIVE_ORDERS.PROJECT:
          num = this.selectedData.projectTable.length;
          break;
      }
      return num;
    },
    showPagination() {
      return this.list.total > 0;
    },
    filterList({ curActiveOrder }) {
      let filterArr = [];
      switch (curActiveOrder) {
        case ACTIVE_ORDERS.CHANNEL:
          filterArr = [
            { keyword: 'orderId', name: '订单编号', placeholder: '可通过粘贴快速填写订单编号，一行代表一个编号', type: 'input', inputType: 'textarea', maxlength: 2000, maxLength: 2000, lengthLimit: true },
            { keyword: 'resourceName', name: '账号', type: 'input' },
            { keyword: 'theme', name: '品牌名称', type: 'input' },
            { keyword: 'orderOperator', name: '执行人', type: 'input' },
            { keyword: 'market', name: '销售', type: 'input' },
            { keyword: 'clientName', name: '客户名称', type: 'input' },
            { keyword: 'clientSettlementId', name: '客户结算单', type: 'input' },
            { keyword: 'taxAmount', name: '含税金额', type: 'inputRange' },
            { keyword: 'orderTime', name: '下单日期', timeType: 'daterange', type: 'rangeDate' },
            // 下拉
            { keyword: 'departmentId', name: '所属部门', type: 'cascaderSelect', childrenVal: 'children', strictly: true, options: this.deptTreeList },
            // { keyword: 'accountBelong', name: '账号归属', type: 'mulSelect', isSearch: true, options: this.accountBelongOptions },
            { keyword: 'orderPlatformId', name: '下单平台', type: 'select', options: this.orderPlatformOption }
          ];
          break;
        case ACTIVE_ORDERS.PROJECT_CHANNEL:
          filterArr = [
            { keyword: 'orderId', name: '订单编号', placeholder: '可通过粘贴快速填写订单编号，一行代表一个编号', type: 'input', inputType: 'textarea', maxlength: 2000, maxLength: 2000, lengthLimit: true },
            { keyword: 'resourceName', name: '账号', labelWidth: '70px', type: 'input' },
            { keyword: 'theme', name: '品牌名称', labelWidth: '70px', type: 'input' },
            { keyword: 'projectName', name: '项目名称', labelWidth: '70px', type: 'input' },
            { keyword: 'orderOperator', name: '执行人', labelWidth: '70px', type: 'input' },
            { keyword: 'market', name: '销售', labelWidth: '70px', type: 'input' },
            { keyword: 'clientName', name: '客户名称', labelWidth: '70px', type: 'input' },
            { keyword: 'orderTime', name: '下单日期', labelWidth: '70px', timeType: 'daterange', type: 'rangeDate' },
            { keyword: 'taxAmount', name: '含税金额', labelWidth: '70px', type: 'inputRange' },
            // 下拉
            { keyword: 'departmentId', name: '所属部门', type: 'cascaderSelect', childrenVal: 'children', strictly: true, options: this.deptTreeList },
            { keyword: 'accountBelong', name: '账号归属', type: 'mulSelect', isSearch: true, options: this.accountBelongOptions },
            { keyword: 'orderPlatformId', name: '下单平台', type: 'select', options: this.orderPlatformOption },
            { keyword: 'projectType', name: '项目类型', type: 'select', options: this.projectTypeOption }
          ];
          break;
        case ACTIVE_ORDERS.PROJECT:
          filterArr = [
            { keyword: 'projectName', name: '项目名称', labelWidth: '70px', type: 'input' },
            { keyword: 'batchProjectNum', name: '订单编号', placeholder: '可通过粘贴快速填写订单编号，一行代表一个编号', type: 'input', inputType: 'textarea', maxlength: 2000, maxLength: 2000, lengthLimit: true },
            { keyword: 'brandName', name: '品牌名称', labelWidth: '70px', type: 'input' },
            { keyword: 'creator', name: '创建人', labelWidth: '70px', type: 'input' },
            { keyword: 'clientName', name: '客户名称', labelWidth: '70px', type: 'input' },
            { keyword: 'taxAmount', name: '含税金额', labelWidth: '70px', type: 'inputRange' },
            { keyword: 'departmentId', name: '所属部门', type: 'cascaderSelect', childrenVal: 'children', strictly: true, options: this.deptTreeList },
            { keyword: 'customerProperty', name: '客户性质', type: 'select', options: clientOption },
            { keyword: 'projectStatus', name: '项目状态', type: 'select', options: statusOption },
            { keyword: 'approvalTime', name: '立项日期', labelWidth: '70px', timeType: 'daterange', type: 'rangeDate' },
            { keyword: 'finishTime', name: '结案日期', labelWidth: '70px', timeType: 'daterange', type: 'rangeDate' },
            { keyword: 'createTime', name: '创建时间', labelWidth: '70px', timeType: 'daterange', type: 'rangeDate' }
          ];
          break;
      }
      return filterArr;
    },
    orderListSetting() {
      return [{
        'name': '订单类型',
        'isShow': true,
        'fieldName': 'orderType'
      }, {
        'name': '订单编号',
        'isShow': true,
        'parentField': 'orderInfo',
        'fieldName': 'orderId'
      }, {
        'name': '下单日期',
        'isShow': true,
        'fieldName': 'orderTime'
      }, {
        'name': '含税金额',
        'isShow': true,
        'fieldName': 'taxAmount'
      }, {
        'name': '订单状态',
        'isShow': true,
        'fieldName': 'orderStatus'
      }, {
        'name': '账号',
        'isShow': true,
        'fieldName': 'resourceName'
      }, {
        'name': '品牌名称',
        'isShow': true,
        'fieldName': 'theme'
      }, {
        'name': '下单平台',
        'isShow': true,
        'fieldName': 'orderPlatform'
      }, {
        'name': '下单形式',
        'isShow': true,
        'fieldName': 'orderForm',
        'parentField': 'orderInfo'
      }, {
        'name': '所属部门',
        'isShow': true,
        'fieldName': 'attributionMatrix'
      }, {
        'name': '账号归属',
        'isShow': true,
        'fieldName': 'accountBelongName',
        'parentField': 'orderInfo'
      }, {
        'name': '执行人',
        'isShow': true,
        'fieldName': 'orderOperator',
        'parentField': 'orderInfo'
      }, {
        'name': '销售',
        'isShow': true,
        'fieldName': 'market'
      }];
    }
  },
  methods: {
    // 首次打开初始化filter下拉列表数据
    onDrawerOpen() {
      this.queryDeptTreeList();
      // this.accountBelongOptionsList();
      this.platformList();
      this.projectTypeList();
    },
    // 所属部门
    queryDeptTreeList() {
      getDepartmentAll().then(res => {
        this.deptTreeList = (res && res.data) || [];
      }).catch(_ => {});
    },
    // 账号归属
    async accountBelongOptionsList() {
      try {
        const result = await getAccountBelong();
        if (result && result.data) {
          result.data.forEach(i => {
            i.label = i.value;
            i.value = i.id;
          });
          this.accountBelongOptions = result.data;
        }
      } catch (error) {
        console.log(error);
      }
    },
    // 下单平台
    async platformList() {
      try {
        const result = await platformList();
        if (result && result.data) {
          result.data.forEach((i) => {
            i.label = i.value;
            i.value = i.id;
          });
          this.orderPlatformOption = result.data;
        }
      } catch (error) {
        console.log(error);
      }
    },
    // 项目类型
    async projectTypeList() {
      this.projectTypeOption.push({ value: -1, label: '全部' });
      try {
        const result = await getProjectTypes({ type: 2 });
        const projectOption = result.data.map(item => {
          return {
            value: item.id,
            label: item.name
          };
        });
        this.projectTypeOption.push(...projectOption);
      } catch (error) {
        console.log(error);
      }
    },
    // 抽屉关闭清空数据
    onDrawerClosed() {
      Object.keys(this.selectedData).forEach(key => {
        this.selectedData[key] = [];
      });
      this.curActiveOrder = ACTIVE_ORDERS.CHANNEL;
      this.curSubActiveOrder = SUB_ACTIVE_ORDERS.ALL_ORDER;
    }
  }
};
